<template>
  <div class="resumeItemContainer">
    <div class="resumeItemTitle">
      <div class="resumeItemTitleFlag"></div>
      <div class="resumeItemTitleContent">求职状态</div>
      <!-- <div class="resumeItemTitleAddIcon">添加</div> -->
    </div>
    <div class="resumeItemMain">
      <div class="resumeItemDisplayList">
        <div class="resumeItemDisplayItem">
          <div class="resumeItemDisplayItemEditButtons">
            <template v-if="!editStatus">
              <span class="resumeItemDisplayItemEditButton" @click="changeEditStatusForSingle(true)">
                <img :src="myResumeEditIcon" /> 编辑</span>
              <!-- <span class="resumeItemDisplayItemEditButton" @click="handleDeletClick()">
                <img :src="myResumeDeleteIcon" />删除</span> -->
            </template>
          </div>
          <div class="displayBlock" v-if="!editStatus">
            <span class="resumeItemDisplayLabel">求职状态：</span>
            <span class="resumeItemDisplayValue">{{ handleStatus(status.type) }}</span>
            <span class="resumeItemDisplayLabel">到岗日期：</span>
            <span class="resumeItemDisplayValue">{{ status.time||"未设置" }}</span>
          </div>
          <div class="editBlock" v-else :id="editStatus?'edittingBlock':''">

            <div class="resumeItemEdit">
              <el-form ref="form" :model="editForm" inline :rules="rules">
                <el-form-item label="求职状态：" prop="type">
                  <el-select v-model="editForm.type" placeholder="请选择求职状态">
                    <el-option v-for="item in aimList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="到岗日期：" prop="time">
                  <el-select v-model="editForm.time" placeholder="请选择到岗日期">
                    <el-option v-for="item in timeAimList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <div class="submitButtons">
                    <el-button size="small" @click="handleCancel">取 消</el-button>
                    <el-button size="small" type="primary" @click="handleSave">完 成</el-button>
                  </div>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</template>
<script>
// 这个模块的数据不和其他数据同一个接口，都需要额外处理
import myResumeItemsMixin from "@/mixin/myResumeItemsMixin.js";
import { aimList, timeAimList } from "@/utils/resumeData";
export default {
  name: "intendedInfo",
  mixins: [myResumeItemsMixin],
  props: {
    resumeData: {
      type: Object,
      default: () => ({}),
    },
    editStatus: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      editForm: {
        type: 4,
        time: "随时",
      },
      status: {},
      aimList,
      timeAimList,
      rules: {
        type: [{ required: true, message: "请选择求职状态", trigger: "blur" }],
        time: [{ required: true, message: "请选择到岗日期", trigger: "blur" }],
      },
    };
  },
  watch: {
    resumeData: {
      handler(newValue, oldValue) {
        //console.log("求职状态intendInfo基本信息更新：", newValue);
        if (newValue && newValue.personInfo) {
          this.status = {
            type:
              +newValue.personInfo.person_status == 0
                ? ""
                : +newValue.personInfo.person_status,
            time: newValue.personInfo.workdate,
          };
          this.editForm = { ...this.status };
        }
      },
    },
  },
  methods: {
    async handleSave() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const finalParams = {
            op: "person_intended_industry_busi",
            func: "updateStatusAndWorkData",
            version: "v7.3.5",
            forName: "iphone",
            person_id: this.personId,
            param: {
              person_id: this.personId,
              conditionArr: {
                person_status: this.editForm.type,
                workdate: this.editForm.time,
              },
            },
          };
          //console.log("修改求职状态：", finalParams);
          this.resumeGeneralInterface(
            finalParams,
            () => {
              this.changeEditStatusForSingle(false);
              this.$emit("reqGetIntenedInfo");
            },
            () => {}
          );
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },
    handleCancel() {
      this.changeEditStatusForSingle(false);
      this.editForm = {
        type: +this.resumeData.personInfo.person_status,
        time: this.resumeData.personInfo.workdate,
      };
    },
    handleDeletClick() {
      //console.log("点击了删除");
    },
    handleStatus(val) {
      let status = aimList.find((ele) => +ele.value === +val);
      return status ? status.label : "未设置";
    },
  },
};
</script>

<style lang="scss" scoped>
.resumeItemContainer {
  display: flex;
  flex-direction: column;
  margin: 20px 0 16px;
  position: relative;
  &:hover {
    .resumeItemDisplayItemEditButtons {
      display: block !important;
    }
  }
  .resumeItemTitle {
    display: flex;
    align-items: center;
    .resumeItemTitleFlag {
      width: 4px;
      height: 19px;
      background: #0b6eff;
      border-radius: 2px;
      margin-right: 10px;
    }
    .resumeItemTitleContent {
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 20px;
      color: #333333;
      margin-right: 19px;
    }
    .resumeItemTitleAddIcon {
      display: flex;
      align-items: center;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 14px;
      color: #4880ff;
      cursor: pointer;
      .resumeItemAddIcon {
        width: 20px;
        height: 20px;
        margin-right: 8px;
      }
    }
  }
  .resumeItemMain {
    margin-top: 16px;
    .resumeItemDisplayList {
      .resumeItemDisplayItem {
        .resumeItemDisplayItemEditButtons {
          display: none;
          position: absolute;
          top: 4px;
          right: 0;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 15px;
          color: #4880ff;
          line-height: 18px;
          & > span {
            display: inline-flex;
            align-items: center;
            cursor: pointer;
            margin-left: 23px;
            user-select: none;
            & > img {
              width: 16px;
              height: 16px;
              margin-right: 5px;
            }
          }
        }
        .displayBlock {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 15px;
          color: #666666;
          line-height: 18px;
          text-align: left;
          font-style: normal;
          &:hover {
            background: #f8f8f8;
            border-radius: 8px;
            padding: 16px;
          }
          .resumeItemDisplayLabel:not(:first-child) {
            margin-left: 78px;
          }
        }
        .editBlock {
          margin-top: 2px;
          background: #f8f8f8;
          border-radius: 8px;
          padding: 16px;
          .editTitle {
            font-family: PingFang-SC, PingFang-SC;
            font-weight: bold;
            font-size: 18px;
            color: #333333;
            line-height: 20px;
            text-align: left;
            font-style: normal;
            margin-bottom: 19px;
          }
          ::v-deep .el-form-item {
            display: inline-flex;
            flex-direction: column;
            min-width: 251px;
            width: calc(33% - 40px);
            margin-right: 24px;
            margin-bottom: 16px;
            margin-top: 0px;
            .el-form-item__label {
              height: 22px;
              font-family: PingFangSC, PingFang SC;
              font-weight: 400;
              font-size: 14px;
              color: #666660;
              line-height: 20px;
              text-align: left;
              font-style: normal;
            }
          }
          .submitButtons {
            display: flex;
            justify-content: flex-end;
            position: relative;
            top: 24px;
            right: 0;
            .el-button {
              display: flex;
              justify-content: center;
              align-items: center;
              width: 100px;
              height: 30px;
              background: #ffffff;
              border-radius: 4px;
              border: 1px solid #cdcdcd;
              font-family: PingFang-SC, PingFang-SC;
              font-weight: bold;
              font-size: 14px;
              text-align: left;
              font-style: normal;
              padding: 0;
              &.el-button--primary {
                width: 100px;
                height: 30px;
                background: #4880ff;
                border-radius: 4px;
              }
            }
          }
        }
      }
    }
  }
}
</style>